<!doctype html>
<html ng-app="my_app">

<head>
    <meta charset="utf-8">
    <title>directive指令</title>
    <script src="./js/angular.js"></script>
    <script src="./js/jquery-1.7.2.js"></script>
    <script>
    var app = angular.module('my_app', []);

    app.directive('changeColor', function() {
        return function(scope, element, attr) {
            var arr = element.children();
            for (var i = 0; i < arr.length; i++) {
                arr[i].style.background = i % 2 ? 'red' : 'yellow';
            }
        };
    });
    </script>
</head>

<body>
    <ul change-color>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</body>

</html>
